package com.sky.web.app;

import com.sky.dto.SetmealPageDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/user/setmeal")
public class AppSetmealController {

    @Autowired
    private SetmealService setmealService;

    // 根据分类id查询套餐列表
    @Cacheable(value = "setmealCache",key="#categoryId")
    @GetMapping("/list")
    public Result list(Long categoryId) {//1. 接收参数
        log.info("查询数据库");
        //2. 封装dto
        SetmealPageDTO dto = new SetmealPageDTO();
        dto.setCategoryId(categoryId);
        dto.setStatus(1);// 启售
        //3. 调用service
        List<SetmealVO> list = setmealService.findList(dto);
        //4. 返回
        return Result.success(list);

    }

    //根据套餐id查询菜品列表
    @GetMapping("/dish/{id}")
    public Result findDishItemsBySetMealId(@PathVariable("id") Long id) {
        List<DishItemVO> dishItemVOList = setmealService.findDishItemsBySetMealId(id);
        return Result.success(dishItemVOList);
    }

}

